﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;

namespace D3StatsClient.Model
{
    public static class D3StatsUtility
    {
        public static string GetGameInstanceServerIp()
        {

            string serverIp = "N/A";
            IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();

            var result = from t in ipProperties.GetActiveTcpConnections()
                         where t.RemoteEndPoint.Port == 1119
                         && t.State == TcpState.Established
                         && !t.RemoteEndPoint.Address.ToString().EndsWith("193")
                         select t;

            foreach (var r in result)
            {
                serverIp = r.RemoteEndPoint.Address.ToString();
            }

            return serverIp;
        }

        public static List<string> DelimitedStringToList(string delimitedString)
        {
            List<string> list = new List<string>();

            try
            {
                return delimitedString.Split(';').ToList<string>();
            }
            catch { }

            return list;

        }
    }
}
